*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
************************ DRÄGER AND NGHIEM (2025) ***********************
*INFLATION LITERACY, INFLAION EXPECTATIONS, AND TRUST IN THE CENTRAL BANK: 
*                           A SURVEY EXPERIMENT 
****************** THE REVIEW OF ECONOMICS AND STATISTICS ***************
*********************** (REPLICATION FILES) *****************************
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

***********************   JANUARY 2025  *******************************

***** Note: Read "README.docx" for details about the code and data ******

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
*** Set STATA
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

*** Clear all ***
clear all
version 18

******************

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
*** Data preparation
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

use "Inflation_literacy_Jan2025_raw.dta" , clear

xtset ID wave

*Demographics

*Dummy for East_Germany

	gen East_Germany =0
	replace East_Germany = 1 if state == 4 | state == 8 | state == 13 |state == 14 | state == 16 
	
	label var East_Germany "East Germany"
	
	label define East_Germany 0 "West" 1 "East" 
	label values East_Germany East_Germany

*Income (euros)
	
	gen inc_cont = income
	recode inc_cont (1 = 500) (2=750) (3= 1250) (4=1750) (5=2250) (6=2750) (7=3250) (8=3750) (9=4500) (10=5500) (11=7000) (12=9000) (13=10000) (999=.)
	
	label var inc_cont "Income (euro)"
	
*Income groups

	gen inc_group = income
	recode inc_group (1/3 =1) (4/6 =2) (7/9=3) (10/13 = 4) (999=.)
	label define inc_group 1 "low_inc" 2 "ml_inc" 3 "mh_inc" 4 "high_inc"
	label values inc_group inc_group
	tab inc_group
	
	gen inc_group2 = inc_group
	replace inc_group2 = 5 if inc_group2 ==.
	label define inc_group2 1 "low_inc" 2 "ml_inc" 3 "mh_inc" 4 "high_inc" 5 "Don't know"
	label values inc_group2 inc_group2
	tab inc_group2
	
	gen inc_dontknow  = (inc_group2 == 5)
	drop inc_group
	
	label var inc_dontknow "Income (no answer)"


*Education groups

	gen edu_group = edu
	recode edu_group (9=1) (3=2) (8=2) (4=3) (5=3) (6=3) (7=3)
	label define edu_group 1 "No degree" 2 "Vocational degree" 3 "College degree" 
	label values edu_group edu_group
	tab edu_group 

*College

	gen college = (edu_group == 3)
	
	label var college "College"
	
	label define college 0 "No" 1 "Yes" 
	label values college college
	
*Renter

	gen renter = house_owner
	recode renter (2/4 = 0) 
	
	label var renter "Renter"
	
*Household size

	gen hhsize_group = hhsize
	replace hhsize_group = l.hhsize_group if hhsize_group ==.
	replace hhsize_group = 6 if hhsize_group  >5
	
	label var hhsize_group "HH size"

*Employment

	gen employment_group = employment
	recode  employment_group (3/6 =0) (7=3) (8/11 =0)
	label define employment_group 0 "Others" 1 "full_time" 2 "part_time" 3 "retired"
	label values employment_group employment_group
		
	gen full_time = (employment_group == 1)
	gen part_time = (employment_group == 2)
	gen retired = (employment_group == 3)
	
	label var full_time "Full time job"
	label var part_time "Part time job"
	label var retired "Retired"
	
*News attention:

*Dummy for inflation news attention

	gen news_inf_att2 = (news_inf == 4 | news_inf == 5 ) // who pay attention to news more than 3 times
	
	label var news_inf_att2 "Inflation news attention"
	
	label define news_inf_att2 0 "less" 1 "more" 
	label values news_inf_att2 news_inf_att2
	
*Dummy for monetary news attention

	gen news_ECB_att3 = (news_ECB == 3 | news_ECB == 4 | news_ECB == 5 ) // who pay attention to news more than 2 times
	
	label var news_ECB_att3 "Monetary news attention"
	
	label define news_ECB_att3 0 "less" 1 "more" 
	label values news_ECB_att3 news_ECB_att3
	
********************************************************************************
* Time spent on treatments

	gen basic_time = basic_treatment if wave == 1
	replace basic_time = 2 if duration_tA < 15 & basic_treatment == 1 & wave == 1
	replace basic_time = 3 if duration_tA > 145 & duration_tA !=. & basic_treatment == 1 & wave == 1

	replace basic_time = l.basic_time if wave == 2
	label define basic_time 0 "Control" 1 "Literacy_normal" 2 "Literacy_short" 3 "Literacy_long"
	label values basic_time basic_time
	
* Compliance: Excluding those who spent less than 15 seconds on the literacy treatment or less than 10 seconds on quantitative treatments

	gen basic_treatment1 = basic_treatment
	replace basic_treatment1 = . if duration_tA < 15
	
	gen further_treatment1 = further_treatment
	replace further_treatment1 = . if t_spent < 10

********************************************************************************

*Inflation literacy and financial literacy
	
	gen literacy1_true = (literacy1 == 1)
	
	gen literacy2_true = (literacy2 == 1)
	
	gen literacy3_true = (literacy3 == 3)
	
	gen literacy4_true = (literacy4 == 1)

	gen literacy5_true = (literacy5 == 4)
	
	gen literacy7_true = (literacy7 == 2)
	
	gen literacy8_true = (literacy8 == 2)
	
	label var literacy1_true "Dummy for correct answer"
	label var literacy2_true "Dummy for correct answer"
	label var literacy3_true "Dummy for correct answer"
	label var literacy4_true "Dummy for correct answer"
	label var literacy5_true "Dummy for correct answer"
	label var literacy7_true "Dummy for correct answer"
	label var literacy8_true "Dummy for correct answer"
	
*Inflation literacy score

	gen literacy_grade_inf = literacy1_true + literacy2_true + literacy3_true + literacy4_true + literacy7_true
	
	label var literacy_grade_inf "Inflation literacy score"
	
*Financial literacy score
	
	gen literacy_fin2 = literacy5_true + literacy8_true
	
	label var literacy_fin2 "Financial literacy score"
	
********************************************************************************

*Inflation point forecasts	(prior forecast)
	
*Exclude the top and bottom 2% of distribution of inflation point forecasts

	local target "inf_perc_point inf_exp1y_point inf_exp3y_point ECB_target"

	foreach y of local target {
	egen `y'_2 = pctile(`y') if wave == 1, p(2)
	egen `y'_98 = pctile(`y') if wave == 1, p(98)
	gen `y'_298 = `y' if wave == 1 
	replace `y'_298 =. if wave == 1 & `y'_298 >`y'_98 | `y'_298 < `y'_2
	}
	
*Dummy for those who know the ECB inflation target of 2%

	gen ECB_target_dummy = 0
	replace ECB_target_dummy = 1 if ECB_target == 2
	
*Calculate weighted average and weighted standard deviation of probabilistics forecasts (posterior forecasts)

* One year ahead

	gen inf_exp1y_prob_noans = v_93 
	gen inf_exp1y_prob_ans = 1- inf_exp1y_prob_noans
	
	label var inf_exp1y_prob_ans "Dummy for answering probabilistics forecast 1 year ahead"
	
	gen prob_exp1y = v_83 +v_84 +v_85 +v_86+ v_87+ v_88 +v_89+ v_90+ v_91+ v_92
	
	gen inf_exp1y_prob = (v_83*(-14)+ v_84*(-10) + v_85*(-6) + v_86*(-3) + v_87*(-1)+ v_88*1 + v_89*3 + v_90*6 + v_91*10 + v_92*14)/100
	replace inf_exp1y_prob =. if prob_exp1y ==0
	
	gen inf_exp1y_var = (v_83*(inf_exp1y_prob+14)^2+ v_84*(inf_exp1y_prob+10)^2 + v_85*(inf_exp1y_prob+6)^2 + v_86*(inf_exp1y_prob+3)^2 + v_87*(inf_exp1y_prob+1)^2+ v_88*(inf_exp1y_prob-1)^2 + v_89*(inf_exp1y_prob-3)^2 + v_90*(inf_exp1y_prob-6)^2 + v_91*(inf_exp1y_prob-10)^2 + v_92*(inf_exp1y_prob-14)^2)^(1/2)
	replace inf_exp1y_var = inf_exp1y_var/10
	
* Three years ahead

	gen inf_exp3y_prob_noans = v_104
	gen inf_exp3y_prob_ans = 1- inf_exp3y_prob_noans
	label var inf_exp3y_prob_ans "Dummy for answering probabilistics forecast 3 year ahead"
	
	gen prob_exp3y = v_94+ v_95 +v_96+ v_97+ v_98+ v_99+ v_100 +v_101 +v_102+ v_103
	tab prob_exp3y
	
	gen inf_exp3y_prob = (v_94*(-14)+ v_95*(-10) + v_96*(-6) + v_97*(-3) + v_98*(-1)+ v_99*1 + v_100*3 + v_101*6 + v_102*10 + v_103*14)/100
	replace inf_exp3y_prob =. if prob_exp3y ==0
	sum inf_exp3y_prob
	
	gen inf_exp3y_var = (v_94*(inf_exp3y_prob+14)^2+ v_95*(inf_exp3y_prob+10)^2 + v_96*(inf_exp3y_prob+6)^2 + v_97*(inf_exp3y_prob+3)^2 + v_98*(inf_exp3y_prob+1)^2+ v_99*(inf_exp3y_prob-1)^2 + v_100*(inf_exp3y_prob-3)^2 + v_101*(inf_exp3y_prob-6)^2 + v_102*(inf_exp3y_prob-10)^2 + v_103*(inf_exp3y_prob-14)^2)^(1/2)
	replace inf_exp3y_var = inf_exp3y_var/10
	
*Generate a dummy for those who chose more than 1 bin when answering probabilistics forecasts

* One year ahead
	local target "v_83 v_84 v_85 v_86 v_87 v_88 v_89 v_90 v_91 v_92" 
	foreach y of local target {
	gen inf_exp1y_bin_`y' = (`y'>0)
	}
	
	gen inf_exp1y_nbins = inf_exp1y_bin_v_83+ inf_exp1y_bin_v_84 + inf_exp1y_bin_v_85 + inf_exp1y_bin_v_86 + inf_exp1y_bin_v_87 + inf_exp1y_bin_v_88 + inf_exp1y_bin_v_89 + inf_exp1y_bin_v_90 + inf_exp1y_bin_v_91 + inf_exp1y_bin_v_92
	
	gen inf_exp1y_nbins_d = inf_exp1y_nbins
	replace inf_exp1y_nbins_d =0 if inf_exp1y_nbins >1
	replace inf_exp1y_nbins_d = . if inf_exp1y_nbins ==0
	drop inf_exp1y_nbins
	
* Three years ahead

	local target "v_94 v_95 v_96 v_97 v_98 v_99 v_100 v_101 v_102 v_103" 
	foreach y of local target {
	gen inf_exp3y_bin_`y' = (`y'>0)
	}
	
	gen inf_exp3y_nbins = inf_exp3y_bin_v_94 + inf_exp3y_bin_v_95 + inf_exp3y_bin_v_96 + inf_exp3y_bin_v_97 + inf_exp3y_bin_v_98 + inf_exp3y_bin_v_99 + inf_exp3y_bin_v_100 + inf_exp3y_bin_v_101 + inf_exp3y_bin_v_102 + inf_exp3y_bin_v_103
	
	gen inf_exp3y_nbins_d = inf_exp3y_nbins
	replace inf_exp3y_nbins_d =0 if inf_exp3y_nbins >1
	replace inf_exp3y_nbins_d = . if inf_exp3y_nbins ==0
	drop inf_exp3y_nbins

********************************************************************************
* Sample selection

*Select sample of those who provide all questions on inflation predictions and trust in the central bank: wave 1
	gen sample_robust_w1 =0 if wave == 1
	replace sample_robust_w1 = 1 if wave == 1 & inf_perc_point !=. & inf_exp1y_point !=. & inf_exp3y_point !=. & inf_exp1y_prob !=. & inf_exp3y_prob !=. & trust_bundesbank!=. & trust_ecb!=.


*Select sample of those who provide all questions on inflation predictions and trust in the central bank: Excluding the top and bottom 2% of distribution of inflation point predictions
	gen sample_robust_w1_298 =0 if wave == 1
	replace sample_robust_w1_298 = 1 if wave == 1 & inf_perc_point_298 !=. & inf_exp1y_point_298 !=. & inf_exp3y_point_298 !=. & inf_exp1y_prob !=. & inf_exp3y_prob !=. & trust_bundesbank!=. & trust_ecb!=.


*Select sample of those who provide all questions on inflation predictions and trust in the central bank: wave 2
	gen sample_robust_w2 =0 if wave == 2
	replace sample_robust_w2 = 1 if wave == 2 & l.inf_perc_point !=. & l.inf_exp1y_point !=. & l.inf_exp3y_point !=. & inf_exp1y_prob !=. & inf_exp3y_prob !=. & trust_bundesbank!=. & trust_ecb!=.


*Select sample of those who provide all questions on inflation predictions and trust in the central bank: Excluding the top and bottom 2% of distribution of inflation point predictions (wave 2)
	gen sample_robust_w2_298 =0 if wave == 2
	replace sample_robust_w2_298 = 1 if wave == 2 & l.inf_perc_point_298 !=. & l.inf_exp1y_point_298 !=. & l.inf_exp3y_point_298 !=. & inf_exp1y_prob !=. & inf_exp3y_prob !=. & trust_bundesbank!=. & trust_ecb!=.	
	
********************************************************************************

save "Inflation_literacy_Jan2025_final.dta" , replace

********************************************************************************
********************************************************************************